/*
 * @Author: 噜噜雯雯 2199987619@qq.com
 * @Date: 2025-05-27 08:43:07
 * @LastEditors: 噜噜雯雯 2199987619@qq.com
 * @LastEditTime: 2025-09-28 09:57:09
 * @FilePath: \linePatrol\vue-element-plus-admin\src\api\role\index.ts
 * @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
 */
import service from '@/axios/http'
import { UserListAlltype, ResetPwdType } from './types'
import { TableIResponse } from '@/utils/Api'
export class GetSystemUserApi {
  async GetAllUser(): Promise<UserListAlltype[]> {
    const result = (await service.get('/api/system/user/listAll')) as unknown as any
    return result.data
  }
  async GetUser(params: any): Promise<TableIResponse<UserListAlltype[]>> {
    const result = (await service.get('/api/system/user/list', { params })) as unknown as any
    return result
  }
  async GetUserDetail(userId: number | undefined): Promise<TableIResponse<UserListAlltype[]>> {
    const result = (await service.get(`/api/system/user/${userId}`)) as unknown as any
    return result
  }
  //删除用户
  async DeletUser(userIds: number): Promise<boolean> {
    const result = (await service.delete(`/api/system/user/${userIds}`)) as unknown as any
    const { code } = result as any
    if (code == 200) {
      return true
    } else {
      return false
    }
  }
  //新增用户
  async AddUser(data: UserListAlltype): Promise<boolean> {
    const result = (await service.post('/api/system/user', data)) as unknown as any
    const { code } = result as any
    if (code == 200) {
      return true
    } else {
      return false
    }
  }
  //修改用户
  async EditUser(data: UserListAlltype): Promise<boolean> {
    const result = (await service.put('/api/system/user', data)) as unknown as any
    const { code } = result as any
    if (code == 200) {
      return true
    } else {
      return false
    }
  }
  //重设用户密码
  async ResetPwd(data: ResetPwdType): Promise<boolean> {
    const result = (await service.put('/api/system/user/resetPwd', data)) as unknown as any
    const { code } = result as any
    if (code == 200) {
      return true
    } else {
      return false
    }
  }
  //  查询岗位与角色列表、
  async GetUserInfo(): Promise<TableIResponse<UserListAlltype[]>> {
    const result = (await service.get(`/api/system/user/`)) as unknown as any
    return result
  }
  //修改个人信息
  async EditPersonInfo(data: UserListAlltype): Promise<boolean> {
    const result = (await service.put('/api/system/user/profile', data)) as unknown as any
    const { code } = result as any
    if (code == 200) {
      return true
    } else {
      return false
    }
  }
  //修改头像
  async EditAvatar(data: { userId?: number; avatar: string }): Promise<boolean> {
    const result = (await service.put('/api/system/user/editAvatar', data)) as unknown as any
    const { code } = result as any
    if (code == 200) {
      return true
    } else {
      return false
    }
  }
  //上传Base64
  async UpBase64(datas: { fileName?: string; base64?: string }): Promise<any> {
    const result = (await service.post('/api/file/upBase64', datas)) as unknown as any
    const { code, data } = result as any
    if (code == 200) {
      return data
    } else {
      return null
    }
  }
}
export default new GetSystemUserApi()
